﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Mole : MonoBehaviour
{
    [HideInInspector]
	public Text scoreText; //5、显示分数的 UI
	public static int score = 0; //5、记录分数的变量
	public GameObject beatenMole; //3、用于显示被打地鼠的对象

	public int Id { get; set; } //3、对应洞口的 ID

	public GameController GameController { get; set; } //3、获得 gameController 的对象

	void Start()
	{
		scoreText = GameObject.Find("ScoreText").GetComponent<Text>();

		GameController = GameObject.FindObjectOfType<GameController>(); //3、获得 gameController 的对象

		Destroy(gameObject, 3f); //2、3 秒钟之后，销毁该地鼠
	}

	void OnMouseDown() //3、敲打地鼠的功能
	{
		score++; //5、加分
		scoreText.text = "Score: " + score; //5、显示分数
		GameController.holes[Id].mole = Instantiate(beatenMole, gameObject.transform.position, Quaternion.identity); //3、产生一个被打地鼠的对象

		Destroy(gameObject); //3、销毁正常的地鼠

		// Debug.Log("OnMouseDown"); //3、测试代码
	}
}
